package com.hhl.springcloud_txlcn_account.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.codingapi.txlcn.common.util.Transactions;
import com.codingapi.txlcn.tc.annotation.DTXPropagation;
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.codingapi.txlcn.tc.annotation.TxcTransaction;
import com.codingapi.txlcn.tracing.TracingContext;
import com.hhl.common.db.domain.Demo;
import com.hhl.springcloud_txlcn_account.mapper.AccountMapper;
import com.hhl.springcloud_txlcn_account.service.AccountService;

@Service
public class AccountServiceImpl implements AccountService {

    private final AccountMapper demoMapper;

    @Autowired
    public AccountServiceImpl(AccountMapper demoMapper) {
        this.demoMapper = demoMapper;
    }

    /**
     * TXC模式 	是框架分析业务SQL提前提交，在需要回滚时生成逆向回滚
     * LCN模式   	是框架代理JDBC Connection实现提交回滚业务
     */
    @Override
//    @TxcTransaction(propagation = DTXPropagation.SUPPORTS)
    @LcnTransaction(propagation = DTXPropagation.SUPPORTS)
    @Transactional
    public String rpc(String value) {
        Demo demo = new Demo();
        demo.setGroupId(TracingContext.tracing().groupId());
        demo.setDemoField(value);
        demo.setAppName(Transactions.getApplicationId());
        demo.setCreateTime(new Date());
        demoMapper.save(demo);

//    	int i= 1/0;
        return "ok-service-account";
    }
}
